﻿// FZsystem.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "FZS.h"

using namespace std;

int main()
{
    //第一步，声明一个问题场景，如洗衣服问题场景washing
    FZsystem washing("Washing mashine system");

    //第二步，向问题场景添加若干个属性集合，同时定义其隶属度函数（梯形函数）参数
    //add_attribute函数参数分别为：属性名称，隶属度分级数量，
    //{各级隶属度名称}，各级隶属度函数参数
    //{x1},梯形左腰靠左下端点横坐标
    //{x2},梯形左腰靠右上端点横坐标
    //{x3},梯形右腰靠左上端点横坐标
    //{x4},梯形右腰靠右下端点横坐标
    //x1==x2（x3==x4）则为直角梯形，x2==x3 则为三角形
    //务必保证x1<=x2<=x3<=x4 且 x1<x4
    washing.add_attribute("污泥", 5, 
        { "度1"  ,"度2" ,"度3"  ,"度4"  ,"度5" },  
        { -100   ,0     ,1.7   ,2.5    ,2.9 },                                              
        { -100   ,1.3   ,2.1   ,3.4    ,4.5 },
        { 0.7    ,1.6   ,2.5   ,3.5    ,100 },
        { 1.9    ,2.2   ,3.1   ,4.9    ,100 }                                                                         
    );//
    washing.add_attribute("重量", 5,
        { "重量1","重量2","重量3","重量4","重量5" },
        { -100   ,0     ,1.2   ,2.1    ,2.5 },
        { -100   ,1.0   ,2.0   ,3.0    ,4.0 },
        { 0.0    ,1.3   ,2.4   ,3.5    ,100 },
        { 1.9    ,2.5   ,3.1   ,4.4    ,100 }
    );

    //第三步，添加想要得到的结论y 以及结论分为那些层级,以及各层级的解模糊中心
    //结论y1; 输出值为i-th结论的 model j 推论结果; modle 0:max,modle 1:avg
    washing.add_result("干净程度", 5, { "净5","净4","净3","净2","净1" }, {-10,-5,0,5,10});
    //washing.add_result("清洗时长", 5, { "1h","2h","3h","4h","5h" }, {-10,-5,0,5,10});//结论y2

    //第四步，添加规则库。参数分别为 规则名称，IF{属性1 AND 属性2}，{属性所属层级}，THEN结论，结论所属层级
    washing.add_rule("干净程度判断1", { "污泥" }, { "度1" }, "干净程度", "净1");
    washing.add_rule("干净程度判断2", { "污泥" }, { "度2" }, "干净程度", "净2");
    washing.add_rule("干净程度判断3", { "污泥" }, { "度3" }, "干净程度", "净3");
    washing.add_rule("干净程度判断4", { "污泥" }, { "度4" }, "干净程度", "净4");
    washing.add_rule("干净程度判断5", { "污泥" }, { "度5" }, "干净程度", "净5");

    //washing.add_rule("干净程度判断1", { "重量" }, { "重量1" }, "干净程度", "干净");
    //washing.add_rule("干净程度判断2", { "重量" }, { "重量2" }, "干净程度", "干净");
    //washing.add_rule("干净程度判断3", { "重量" }, { "重量3" }, "干净程度", "干净");
    //washing.add_rule("干净程度判断4", { "重量" }, { "重量4" }, "干净程度", "一般");
    //washing.add_rule("干净程度判断5", { "重量" }, { "重量5" }, "干净程度", "不干净");

    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度1","重量1" }, "清洗时长", "1h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度1","重量2" }, "清洗时长", "2h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度1","重量3" }, "清洗时长", "3h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度1","重量4" }, "清洗时长", "4h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度1","重量5" }, "清洗时长", "5h");

    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度2","重量1" }, "清洗时长", "2h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度2","重量2" }, "清洗时长", "3h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度2","重量3" }, "清洗时长", "3h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度2","重量4" }, "清洗时长", "4h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度2","重量5" }, "清洗时长", "5h");

    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度3","重量1" }, "清洗时长", "3h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度3","重量2" }, "清洗时长", "4h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度3","重量3" }, "清洗时长", "4h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度3","重量4" }, "清洗时长", "5h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度3","重量5" }, "清洗时长", "5h");

    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度4","重量1" }, "清洗时长", "4h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度4","重量2" }, "清洗时长", "4h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度4","重量3" }, "清洗时长", "4h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度4","重量4" }, "清洗时长", "5h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度4","重量5" }, "清洗时长", "5h");

    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度5","重量1" }, "清洗时长", "4h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度5","重量2" }, "清洗时长", "4h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度5","重量3" }, "清洗时长", "5h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度5","重量4" }, "清洗时长", "5h");
    //washing.add_rule("污泥所需清洗时长1", { "污泥","重量" }, { "度5","重量5" }, "清洗时长", "5h");


    //for (int m = 0; m < washing.outs.size(); m++)
    //{
    //    for (int i = -1; i < 7; i++)
    //    {
    //        for (int j = -1; j < 7; j++)
    //        {
    //            vector<double> x;
    //            x.push_back(i);
    //            x.push_back(j);
    //            //FZreasoning 输入的数组x内以此为各个属性的对应输入量
    //            //FZreasoning 返回y[i][j]：yi结论的 model j 结论值。0<=y[i][j]<=yi结论层级数目-1
    //            vector<vector<double>> y = washing.FZreasoning(x);
    //            vector<vector<int>> int_y = washing.result_to_int(y);//将连续的结果值转化为四舍五入的离散值
    //            //cout << "xy=" << i << j << ",max:" << y[m][0] << ",avg:" << y[m][1] << endl;
    //            printf("%.1f|%.2f|%d  ",y[m][0],y[m][1], int_y[m][1]);
    //        }
    //        cout << endl;
    //    }
    //    cout << "------------------------------------" << endl;
    //}

                vector<double> x;
                x.push_back(20);
                x.push_back(4.5);
                //FZreasoning 输入的数组x内以此为各个属性的对应输入量
                //FZreasoning 返回y[i][j]：yi结论的 model j 结论值。0<=y[i][j]<=yi结论层级数目-1
                vector<vector<double>> y = washing.FZreasoning(x);
                vector<vector<int>> int_y = washing.result_to_int(y);//将连续的结果值转化为四舍五入的离散值
                //cout << "xy=" << i << j << ",max:" << y[m][0] << ",avg:" << y[m][1] << endl;
                printf("max,%.1f|avg,%.2f|intavg,%d  ",y[0][0],y[0][1], int_y[0][1]);

    //cout << 0;
}
